using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Deepcode.Flux.Core.Data;

namespace Deepcode.Flux.Core.Systems.CMS.DataTaxonomy
{
	/// <summary>
	/// Represents a single node in the data taxonomy tree
	/// </summary>
	public class DataTaxonomyNode
	{
		// Private field storage
		private int _PK_ID = -1;
		private int _FK_ParentID = -1;
		private string _Name = "";
		// Public property accessors
		public int PK_ID { get { return _PK_ID; } set { _PK_ID = value; } }
		public int FK_ParentID{ get{ return _FK_ParentID; } set{ _FK_ParentID = value; }}
		public string Name { get { return _Name; } set { _Name = value; } }
		
		
		/// <summary>
		/// Returns an array of child nodes
		/// </summary>
		public DataTaxonomyNode [] Children
		{
			get
			{
				return ((new DataTaxonomyTree()).GetForParentID( this.PK_ID ));
			}
		}
		/// <summary>
		/// Returns the parent taxonomy node
		/// </summary>
		public DataTaxonomyNode Parent
		{
			get
			{
				return ((new DataTaxonomyTree()).GetByID( this.FK_ParentID ));
			}
		}

		// Default constructor		
		public DataTaxonomyNode() { }

		// Constructor loading data
		public DataTaxonomyNode(DataRow LoadRow)
		{
			_PK_ID = SQLUtility.DBNull(LoadRow["PK_ID"], -1);
			_FK_ParentID = SQLUtility.DBNull(LoadRow["FK_ParentID"], -1);
			_Name = SQLUtility.DBNull(LoadRow["Name"], "");
		}
	}
}
